<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src/ux/Ux.Encrypt.js - Zero UI Doc</title>
    <meta name="description" content="Zero UI前端文档工具">
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/css/custom.css">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="../assets/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../assets/css/theme.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600,700" rel="stylesheet" type="text/css">
    <link rel="shortcut icon" type="image/png" href="../assets/img/favicon.png">
    
</head>
<body>
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <div class="navbar-header">
          <a href="../" class="navbar-brand">
            <img src="../assets/img/mdeditor-logo.png" alt="">
            <span>API Docs</span>
          </a>
        </div>

        <div class="collapse navbar-collapse" id="nav">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="https://github.com/silentbalanceyh/vertx-ui.git" class="fa fa-github github"></a></li>
          </ul>
        </div>
      </div>
    </nav>
    <div id="main-wrapper" class="row">
        <div id="content-wrapper">
            <ol class="panel-group" id="sidebar" role="tablist" aria-multiselectable="true">
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-search-heading">
                        <h4 class="panel-title">
                      <a role="button" data-toggle="collapse" href="#sidebar-search" aria-expanded="true" aria-controls="collapseOne">
                        Search
                      </a>
                    </h4>
                    </div>
                    <div id="sidebar-search" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-search-heading">
                        <div class="panel-body">
                            <div id="api-tabview-filter">
                                <input type="search" id="api-filter" placeholder="Search...">
                            </div>
                        </div>
                    </div>
                </li>
                    <li class="panel panel-default">
                        <div class="panel-heading" role="tab" id="sidebar-version-heading">
                            <h4 class="panel-title">
                                <a role="button" href="https://github.com/silentbalanceyh/vertx-ui.git/commits/0" target="_blank">
                                  Tag: 0.1.0
                                </a>
                            </h4>
                        </div>
                    </li>
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-modules-heading">
                        <h4 class="panel-title">
                    <a role="button" data-toggle="collapse" href="#sidebar-modules" aria-expanded="true" aria-controls="collapseOne">
                      Modules
                    </a>
                  </h4>
                    </div>
                    <div id="sidebar-modules" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-modules-heading">
                        <div class="panel-body">
                                <ol>
                                        <li>
                                            <a href="../modules/Ux.html">Ux</a>
                                        </li>
                                </ol>
                        </div>
                    </div>
                </li>
            
                <li class="panel panel-default">
                    <div class="panel-heading" role="tab" id="sidebar-classes-heading">
                        <h4 class="panel-title">
                      <a role="button" data-toggle="collapse" href="#sidebar-classes" aria-expanded="true" aria-controls="collapseOne">
                        Classes
                      </a>
                    </h4>
                    </div>
                    <div id="sidebar-classes" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="sidebar-classes-heading">
                        <div class="panel-body">
                            <ol>
                                    <li>
                                        <a href="../classes/Action.html">Action</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Ajax.html">Ajax</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Attribute.html">Attribute</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Column.html">Column</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Debug.html">Debug</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Depend.html">Depend</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Dialog.html">Dialog</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Encrypt.html">Encrypt</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Env.html">Env</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Expr.html">Expr</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Field.html">Field</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Format.html">Format</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Global.html">Global</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Hoc.html">Hoc</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Html.html">Html</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Icon.html">Icon</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Jsx.html">Jsx</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Log.html">Log</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Normalize.html">Normalize</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Op.html">Op</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Option.html">Option</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Param.html">Param</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Prop.html">Prop</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Random.html">Random</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Redux.html">Redux</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Sorter.html">Sorter</a>
                                    </li>
                                    <li>
                                        <a href="../classes/State.html">State</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Store.html">Store</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Type.html">Type</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Validator.html">Validator</a>
                                    </li>
                                    <li>
                                        <a href="../classes/Value.html">Value</a>
                                    </li>
                            </ol>
                        </div>
                    </div>
                </li>
            </ol>
            <div class="content-container">
                <div class="apidocs">
                    <div id="docs-main">
                        <div class="content">
<div class="page-header">
    <h1><i class="fa fa-file-code-o" aria-hidden="true"></i>  File</h1>
</div>

<div class="file">
    <pre class="prettyprint linenums">
import CryptoJS from &#x27;crypto-js&#x27;;

const _toInt64Bytes = (x) =&gt; {
    const bytes = [];
    for (let i = 7; i &gt;= 0; i--) {
        bytes[i] = x &amp; 0xff;
        x = x &gt;&gt; 8;
    }
    return bytes;
};

const _toHexStr = (bytes) =&gt; {
    let hex = [];
    for (let i = 0; i &lt; bytes.length; i++) {
        hex.push((bytes[i] &gt;&gt;&gt; 4).toString(16));
        hex.push((bytes[i] &amp; 0xF).toString(16));
    }
    return hex.join(&quot;&quot;);
};
/**
 * MD5加密函数，针对value进行MD5加密（全大小）
 * @method encryptMD5
 * @param value 被加密字符串
 * @return {String}
 */
const encryptMD5 = (value) =&gt; {
    if (value) {
        return CryptoJS.MD5(String(value)).toString().toUpperCase();
    } else {
        return &quot;&quot;;
    }
};
/**
 * Base64编码函数，针对value进行Base64编码
 * @method encryptBase64
 * @param value 被编码字符串
 * @return {String}
 */
const encryptBase64 = (value) =&gt; {
    return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(value));
};
/**
 * Base64解码函数，针对value进行Base64解码
 * @method decryptBase64
 * @param value 被解码字符串
 * @return {String}
 */
const decryptBase64 = (value) =&gt; {
    return CryptoJS.enc.Base64.parse(value).toString(CryptoJS.enc.Utf8);
};
/**
 * 数字签名专用Hmac512算法加密，针对value和secret一起进行Hmac512数字签名加密
 * @method encryptHmac512
 * @param value 被签名字符串
 * @param secret 随机密钥
 * @return {String}
 */
const encryptHmac512 = (value, secret) =&gt; {
    const raw = CryptoJS.HmacSHA512(value, secret);
    const wordArr = raw.words;
    let retVal = &quot;&quot;;
    for (let idx = 0; idx &lt; wordArr.length; idx++) {
        const bytes = _toInt64Bytes(wordArr[idx]);
        const hexStr = _toHexStr(bytes);
        // 读取低8位
        retVal += hexStr.toUpperCase().substring(8, 16);
    }
    return retVal;
};
/**
 * @class Encrypt
 * @description 加密、编码、解码函数
 */
export default {
    // MD5加密
    encryptMD5,
    // Base64加密
    encryptBase64,
    // Base64解密
    decryptBase64,
    // SHA512签名
    encryptHmac512
}

    </pre>
</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../assets/vendor/prettify/prettify-min.js"></script>
    <script>prettyPrint();</script>
    <script src="../assets/vendor/jquery/jquery.min.js"></script>
    <script src="../assets/vendor/jquery-ui/jquery-ui.min.js"></script>
    <script src="../assets/vendor/bootstrap/js/bootstrap.js"></script>
    <script src="../assets/vendor/github-slugger/slugger.js"></script>
    <script src="../assets/js/yuidoc-bootstrap.js"></script>
</body>
</html>
